package cn.px.crm.msg.service.impl;

import cn.px.common.utils.DateUtils;
import cn.px.common.utils.SecurityUtils;
import cn.px.crm.msg.domain.CrmMsg;
import cn.px.crm.msg.mapper.CrmMsgMapper;
import cn.px.crm.msg.service.ICrmMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 消息Service业务层处理
 *
 * @author ruoyi
 * @date 2022-07-16
 */
@Service
public class CrmMsgServiceImpl implements ICrmMsgService
{
    @Autowired
    private CrmMsgMapper crmMsgMapper;

    /**
     * 查询消息
     *
     * @param id 消息主键
     * @return 消息
     */
    @Override
    public CrmMsg selectCrmMsgById(Long id)
    {
        return crmMsgMapper.selectCrmMsgById(id);
    }

    /**
     * 查询消息列表
     *
     * @param crmMsg 消息
     * @return 消息
     */
    @Override
    public List<CrmMsg> selectCrmMsgList(CrmMsg crmMsg)
    {
        return crmMsgMapper.selectCrmMsgList(crmMsg);
    }
    @Override
    public List<CrmMsg> selectCrmMsgListNew(CrmMsg crmMsg)
    {
        return crmMsgMapper.selectCrmMsgListNew(crmMsg);
    }
    @Override
    public List<CrmMsg> selectCrmMsgListCount(CrmMsg crmMsg)
    {
        return crmMsgMapper.selectCrmMsgListCount(crmMsg);
    }
    @Override
    public List<CrmMsg> selectCrmMsgListCountUpdate(CrmMsg crmMsg)
    {
        return crmMsgMapper.selectCrmMsgListCountUpdate(crmMsg);
    }

    /**
     * 新增消息
     *
     * @param crmMsg 消息
     * @return 结果
     */
    @Override
    public int insertCrmMsg(CrmMsg crmMsg)
    {
        crmMsg.setCreateTime(DateUtils.getNowDate());
        if("1".equals(crmMsg.getNotMe())){
            crmMsg.setCreateBy("1");
        }else {
            crmMsg.setCreateBy(SecurityUtils.getUserId().toString());
        }
        return crmMsgMapper.insertCrmMsg(crmMsg);
    }

    /**
     * 修改消息
     *
     * @param crmMsg 消息
     * @return 结果
     */
    @Override
    public int updateCrmMsg(CrmMsg crmMsg)
    {
        crmMsg.setUpdateTime(DateUtils.getNowDate());
        return crmMsgMapper.updateCrmMsg(crmMsg);
    }
    @Override
    public int updateMsgRead(CrmMsg crmMsg)
    {
        crmMsg.setUpdateTime(DateUtils.getNowDate());
        return crmMsgMapper.updateMsgRead(crmMsg);
    }

    /**
     * 批量删除消息
     *
     * @param ids 需要删除的消息主键
     * @return 结果
     */
    @Override
    public int deleteCrmMsgByIds(Long[] ids)
    {
        return crmMsgMapper.deleteCrmMsgByIds(ids);
    }

    /**
     * 删除消息信息
     *
     * @param id 消息主键
     * @return 结果
     */
    @Override
    public int deleteCrmMsgById(Long id)
    {
        return crmMsgMapper.deleteCrmMsgById(id);
    }
}
